package game.farming.model;

import game.farming.ui.Player;
import java.util.Vector;

public class OptionToBuy{
	public static OptionToBuy OTB_HAY = new OptionToBuy(Product.HAY, "10 Acres of Hay\n$20,000", 20000, 10);
	public static OptionToBuy OTB_GRAIN = new OptionToBuy(Product.GRAIN, "10 Acres of Grain\n$20,000", 20000, 10);
	public static OptionToBuy OTB_FRUIT = new OptionToBuy(Product.FRUIT, "5 Acres of Fruit\n$25,000", 25000, 5);
	public static OptionToBuy OTB_COWS = new OptionToBuy(Product.COWS, "10 Cows\n$5,000", 5000, 10);
	public static OptionToBuy OTB_TRACTOR = new OptionToBuy(Product.TRACTOR, "Tractor\n$10,000", 10000, 1);
	public static OptionToBuy OTB_HARVESTOR = new OptionToBuy(Product.HARVESTOR, "Harvester\n$10,000", 10000, 1);
	public static OptionToBuy OTB_R1 = new OptionToBuy(Product.R1, "Ridge 1", 20000, 1);
	public static OptionToBuy OTB_R2 = new OptionToBuy(Product.R2, "Ridge 2", 30000, 1);
	public static OptionToBuy OTB_R3 = new OptionToBuy(Product.R3, "Ridge 3", 40000, 1);
	public static OptionToBuy OTB_R4 = new OptionToBuy(Product.R4, "Ridge 4", 50000, 1);
	
	private Product product;
	private int price;
	private int quantity;
	private String message;
	
	public OptionToBuy(Product product, String message, int price, int quantity){
		this.product = product;
		this.message = message;
		this.price = price;
		this.quantity = quantity;
	}
	
	public void buy(Player p){
		if(p.getCash() * 5 > price){
			p.addCash(-price);
			Vector<Product> products = p.getProducts();
			for(int i = 0; i < quantity; i++){
				products.add(product);
			}
			if(product.equals(Product.R1)){
				addRanchCows(p, 20);
			}
			else if(product.equals(Product.R2)){
				addRanchCows(p, 30);
			}
			else if(product.equals(Product.R3)){
				addRanchCows(p, 40);
			}
			else if(product.equals(Product.R4)){
				addRanchCows(p, 50);
			}
		}
	}
	
	private void addRanchCows(Player p, int num){
		Vector<Product> products = p.getProducts();
		for(int i = 0; i < num; i++){
			products.add(Product.COWS);
		}
	}
	
	public Product getProduct(){
		return product;
	}
	
	public void setProduct(Product product){
		this.product = product;
	}
	
	public int getPrice(){
		return price;
	}
	
	public void setPrice(int price){
		this.price = price;
	}
	
	public int getQuantity(){
		return quantity;
	}
	
	public void setQuantity(int quantity){
		this.quantity = quantity;
	}
	
	public String getMessage(){
		return message;
	}
	
	public void setMessage(String message){
		this.message = message;
	}
	
}
